package com.mayikt.zuul.handler.factory;

import com.mayikt.core.util.SpringContextUtil;
import com.mayikt.zuul.handler.GatewayHandler;
import com.mayikt.zuul.handler.impl.ApiAuthorityHandler;
import com.mayikt.zuul.handler.impl.ApiCheckTokenHandler;
import lombok.extern.slf4j.Slf4j;


/**
 * 使用工厂获取Handler
 */
@Slf4j
public class FactoryHandler {

    public static GatewayHandler getOneHandler(){
        log.info(">>>>>>>开始装载责任链对象...");
        GatewayHandler blacklistHandler = (GatewayHandler) SpringContextUtil.getBean("blacklistHandler");
        GatewayHandler apiAuthorityHandler = (GatewayHandler) SpringContextUtil.getBean(ApiAuthorityHandler.class);
        GatewayHandler apiCheckTokenHandler = (GatewayHandler) SpringContextUtil.getBean(ApiCheckTokenHandler.class);
        blacklistHandler.setNextHandler(apiAuthorityHandler);
        apiAuthorityHandler.setNextHandler(apiCheckTokenHandler);
        apiCheckTokenHandler.setNextHandler(null);

        return blacklistHandler;
    }
}
